When B8601DT and B8601DA informats read date fields missing the month or day portions, a value of 1 is to be supplied. For example, if '2009' is read with B8601DT, SAS creates a value of 01JAN2009:00:00. If '200905' is read with B8601DT, the value becomes 01MAY2009:00:00.
If a single hyphen is in the data value, as in 2009-05, SAS reads it incorrectly. If the value with the hyphen is the first input value for the column, the result is a missing value. If not the first, SAS can pick up leftover data in the buffer from a previous value.
A workaround is to compress out the hyphens and colons as shown in this example.
final_date=input(compress(orig_date,'-: '),b8601dt.);
ORIG_DATE is a date value with hyphens, colons, and/or spaces.
Because hyphens are not being handled properly, a datetime value containing a negative GMT offset is not read properly. Values with positive offsets are read correctly. See Full Code tab for an example.
The B8601DT informat was renamed from ND8601DT. The documentation states that a "T" is required between the date and time portions. However, this was not being enforced by the informat. When the hotfix was built, this detail was discovered and was fixed. This hotfix caused data being read without the T in the value to be rejected by the informat. When this occurs, it is not necessary to back out of the hotfix. Simply change the informat to B8601DJ (reads Java datetime) because it does not require a T in the datetime value.
When the B8601TM informat specifies a width larger than the value being read, an incorrect result may be created. For example, specifying B8601TM8. to read a value with a width of six produces an incorrect result.
Product Family | Product | System | SAS Release | |
Reported | Fixed* | |||
SAS System | Base SAS | z/OS | 9.1 TS1M0 | 9.3 TS1M1 |
Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.1 TS1M0 | 9.3 TS1M1 | ||
Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.1 TS1M0 | 9.3 TS1M1 | ||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.1 TS1M0 | 9.3 TS1M1 | ||
Microsoft Windows 2000 Advanced Server | 9.1 TS1M0 | |||
Microsoft Windows 2000 Datacenter Server | 9.1 TS1M0 | |||
Microsoft Windows 2000 Server | 9.1 TS1M0 | |||
Microsoft Windows 2000 Professional | 9.1 TS1M0 | |||
Microsoft Windows NT Workstation | 9.1 TS1M0 | |||
Microsoft Windows Server 2003 Datacenter Edition | 9.1 TS1M0 | 9.3 TS1M1 | ||
Microsoft Windows Server 2003 Enterprise Edition | 9.1 TS1M0 | 9.3 TS1M1 | ||
Microsoft Windows Server 2003 Standard Edition | 9.1 TS1M0 | 9.3 TS1M1 | ||
Microsoft Windows XP Professional | 9.1 TS1M0 | 9.3 TS1M1 | ||
64-bit Enabled AIX | 9.1 TS1M0 | 9.3 TS1M1 | ||
64-bit Enabled HP-UX | 9.1 TS1M0 | 9.3 TS1M1 | ||
64-bit Enabled Solaris | 9.1 TS1M0 | 9.3 TS1M1 | ||
HP-UX IPF | 9.1 TS1M0 | 9.3 TS1M1 | ||
Linux | 9.1 TS1M0 | 9.3 TS1M1 | ||
OpenVMS Alpha | 9.1 TS1M0 | 9.3 TS1M1 | ||
Tru64 UNIX | 9.1 TS1M0 | 9.3 TS1M1 |
data dates;
input orig_date : $20.;
datalines;
2004-10-07T07:40
2004-07-16T13
2004-09-21
2009-08
2007
;
run;
proc print;
run;
data result;
set dates;
final_date=input(strip(orig_date),b8601dt.);
format final_date datetime20.;
run;
proc print;run;
/* Program illustrating problem with B8601DA informat when month or day*/
/* is not provided. The day value is not provided in this example. */ */
data a;
input State:$2. date :B8601DA. AGE&$10. A B C D E;
format month yymmn.;
datalines;
IA 201207 0 - 5 0 39 0 119 158
IA 201208 0 - 5 0 47 0 122 169
;
proc print;
run;
/*************************************************************/
/*This code is a workaround for the problem caused by hyphens */
final_date=input(compress(orig_date,'-: '),b8601dt.);
/*************************************************************/
data a;
minus='20111024T135400-0400';
plus='20111024T135400+0400';
dtminus=input(minus,B8601dz20.);
dtplus=input(plus,B8601dz20.);
format dtminus dtplus datetime21.;
proc print;
run;
/*************************************************************************/
/* This code shows that TTT is not the correct output due to reading the */
/* value with the incorrect width. If the width is six instead of eight, */
/* the value of TTT is correct. Also, if two spaces are added to the */
/* macro variable value, it produces the correct value. */
%let PRD_TTM=103300;
data a;
time=1;
ttt=input("&PRD_TTM.",B8601TM8.);
if Time>ttt then aa="1";
proc print;
run;
/* Results from code without COMPRESS function */ Obs orig_date final_date 1 2004-10-07T07:40 07OCT2004:07:40:00 2 2004-07-16T13 16JUL2004:13:00:00 3 2004-09-21 21SEP2004:00:00:00 4 2009-08 21AUG2009:00:00:00 5 2007 01JAN2007:00:00:00 /* Results for DATA step when day value is not present for Date variable*/ Obs State Date Age A 1 IA . 0-5 0 2 IA . 0-5 0 /* Results after workaround */ Obs orig_date final_date 1 2004-10-07T07:40 07OCT2004:07:40:00 2 2004-07-16T13 16JUL2004:13:00:00 3 2004-09-21 21SEP2004:00:00:00 4 2009-08 01AUG2009:00:00:00 5 2007 01JAN2007:00:00:00 /* Results from reading the negative offset with B8601DZ */ Obs minus plus dtminus dtplus 1 20111024T135400-0400 20111024T135400+0400 . 24OCT2011:09:54:00 /* Results from code that reads value with B8601TM. informat */ Obs time ttt aa 1 1 37980
A fix for this issue for Base SAS 9.21_M3 is available at:
http://ftp.sas.com/techsup/download/hotfix/HF2/B25.html#43337A fix for this issue for Base SAS 9.3 is available at:
https://tshf.sas.com/techsup/download/hotfix/HF2/E80.html#43337Type: | Problem Note |
Priority: | high |
Topic: | SAS Reference ==> Informats ==> Date and Time |
Date Modified: | 2012-10-19 15:55:49 |
Date Created: | 2011-05-24 08:58:44 |